package cz.edukomplex.kosilka.client.content;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.SpanElement;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Widget;

public class ConfirmDialog extends Composite {

	private static ConfirmDialogUiBinder uiBinder = GWT
			.create(ConfirmDialogUiBinder.class);
	
	@UiField DialogBox dialogBox;
	@UiField Button okButton;
	@UiField Button cancelButton;
	@UiField SpanElement text;
	
	private boolean choice = false;
	
	interface ConfirmDialogUiBinder extends UiBinder<Widget, ConfirmDialog> {
	}

	public ConfirmDialog(String title, String text) {				
		initWidget(uiBinder.createAndBindUi(this));
		this.text.setInnerHTML(text);
		dialogBox.setText(title);		
		dialogBox.center();
		dialogBox.show();
	}
	
	
	@UiHandler("okButton")
	public void handleOkButton(ClickEvent e){
		dialogBox.hide();
		this.choice = true;
	}
	
	@UiHandler("cancelButton")
	public void handleCancelButton(ClickEvent e){
		dialogBox.hide();
		this.choice = false;
	}
	
	public boolean getChoice(){
		return choice;
	}
}
